package com.servingcloud.servera.modules.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.servingcloud.common.model.RestPage;
import com.servingcloud.servera.modules.dao.UserInfoMapper;
import com.servingcloud.servera.modules.entity.UserInfo;
import com.servingcloud.servera.modules.model.UserInfoMODIFY;
import com.servingcloud.servera.modules.model.UserInfoQUERY;
import com.servingcloud.servera.modules.model.UserInfoSAVE;
import com.servingcloud.servera.modules.service.UserInfoService;
import com.servingcloud.servera.utils.BeanCopierWrapper;
import com.servingcloud.servera.utils.IdGenerator;

@Service
public class UserInfoServiceImpl implements UserInfoService{

	@Autowired
	UserInfoMapper userInfoMapper;
	@Autowired
	IdGenerator idGenerator;//生成id
	public RestPage<UserInfo> findUserInfoPage(UserInfoQUERY query){
		PageHelper.startPage(query.getPageNo(), query.getPageSize());
		List<UserInfo> userList = userInfoMapper.findUserInfoPage(query);
		PageInfo<UserInfo> pageInfo = new PageInfo<>(userList);
		RestPage<UserInfo> page = new RestPage<UserInfo>();
		page.setTotal(pageInfo.getTotal());
		page.add(pageInfo.getList());
		return page;
	}
	@Override
	public Long saveUserInfo(UserInfoSAVE param) {
		UserInfo obj = new UserInfo();
		BeanCopierWrapper.copy(param, obj);
		obj.setUserId(idGenerator.nextId());
		userInfoMapper.insert(obj);
		return obj.getUserId();
	}
	@Override
	public void modifyUserInfo(UserInfoMODIFY param) {
		userInfoMapper.update(param);
	}
	@Override
	public void deleteUserInfo(UserInfoMODIFY param) {
		UserInfo obj = new UserInfo();
		BeanCopierWrapper.copy(param, obj);
		userInfoMapper.delete(obj);
	}
}